package system.base;

import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

import framework.core.Conditions;
import framework.core.DBConnection;
import framework.core.DBData;
import framework.core.DBEngine;
import framework.core.DBResult;
import framework.core.ObjectList;
import framework.core.SearchEvent;
import framework.core.Value;

public class ProductOutCategory extends DBData {
	public static final int DEFAULT_PAGE_SIZE = 20 ;

	private int m_page_size = DEFAULT_PAGE_SIZE ;
	private int m_page_num = 1 ;
	private Map tResult = null;
	private String m_id = ""; // 序号

	private String m_product_id = ""; // 产品ID

	private String m_create_user_id = ""; // 创建人序号

	private String m_create_user = ""; // 创建人

	private String m_create_time = ""; // 创建时间

	private String m_status = ""; // 是否有效
	private String out_type = "" ; //
	
	private String productCode="";
	
	private String productName="";
	
	private String spec="";
	private String model="";
	public void setPageNum(int v)
	{
		m_page_num = v;
	}
	public void setPageSize(int v)
	{
		if(v>0)
		{
			m_page_size = v ;
		}
		else if(v==Value.NULL_INT)
		{
			m_page_size=Value.NULL_INT;
		}
		else	
		{
			m_page_size = DEFAULT_PAGE_SIZE;
		}
	}
	public int getPageNum()
	{
		return m_page_num;
	}
	public int getPageSize()
	{
		return m_page_size;
	}
	
	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getSpec() {
		return spec;
	}

	public void setSpec(String spec) {
		this.spec = spec;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getOut_type() {
		return out_type;
	}

	public void setOutType(String out_type) {
		this.out_type = out_type;
	}

	public String getOutCategory() {
		return out_category;
	}

	public void setOutCategory(String out_category) {
		this.out_category = out_category;
	}


	private String out_category="";
	
	private String m_last_update_user_id = ""; //最后修改人序号

	private String m_last_update_user = ""; //最后修改人

	private String m_last_update_time = ""; //最后修改时间
	
	
    public String getM_last_update_user_id() {
		return m_last_update_user_id;
	}

	public void setM_last_update_user_id(String m_last_update_user_id) {
		this.m_last_update_user_id = m_last_update_user_id;
	}

	public String getM_last_update_user() {
		return m_last_update_user;
	}

	public void setM_last_update_user(String m_last_update_user) {
		this.m_last_update_user = m_last_update_user;
	}

	public String getM_last_update_time() {
		return m_last_update_time;
	}

	public void setM_last_update_time(String m_last_update_time) {
		this.m_last_update_time = m_last_update_time;
	}


	public String getId()
	{
		return m_id;
	}
	public void setId(String v)
	{
		m_id = v;
	}
	

	public String getCreateUserId()
	{
		return m_create_user_id;
	}
	public void setCreateUserId(String v)
	{
		m_create_user_id = v;
	}
	

	public String getCreateUser()
	{
		return m_create_user;
	}
	public void setCreateUser(String v)
	{
		m_create_user = v;
	}
	

	public String getCreateTime()
	{
		return m_create_time;
	}
	public void setCreateTime(String v)
	{
		m_create_time = v;
	}
	
	
	public String getProductId()
	{
	    return m_product_id;
	}
	public void  setProductId(String v)
	{
		m_product_id = v ;
	}
	
	

	

	public String getStatus()
	{
		return m_status;
	}
	public void setStatus(String v)
	{
		m_status = v;
	}
	

	public void initObject(ResultSet rs) throws Exception {
		 m_id = getString(rs, "ID");

		 m_product_id = getString(rs, "PRODUCT_ID"); // 产品ID

		 m_create_user_id = getString(rs, "CREATE_USER_ID"); // 创建人序号

		 m_create_user = getString(rs, "CREATE_USER"); // 创建人

		 m_create_time = getString(rs, "CREATE_TIME"); // 创建时间

		 m_status = getString(rs, "STATUS"); // 是否有效
		
		m_last_update_user_id = getString(rs,"LAST_UPDATE_USER_ID");

		m_last_update_user = getString(rs,"LAST_UPDATE_USER");

		m_last_update_time = getString(rs,"LAST_UPDATE_TIME");
		
		out_category=getString(rs, "OUT_CATEGORY");
		if(tResult==null){
			getAllOutCategory();
		}
		if(tResult.containsKey(out_category)){
			out_category=(String)tResult.get(out_category);
		}
		out_type=getString(rs, "OUT_TYPE");

	}
    public Map getAllOutCategory() {
    	if(tResult==null){
    		tResult = new HashMap();
    		tResult.put( "01310010001", "通用件");
        	tResult.put( "01310010002", "总成组领用");
        	tResult.put( "01310010003", "油料领用");
        	tResult.put( "01310010004", "车身组领用");
        	tResult.put( "01310010005", "肇事组领用");
        	tResult.put( "01310010006", "车身高保");
        	tResult.put( "01310010007", "轮胎");
        	tResult.put( "01310010008", "电瓶");
        	tResult.put( "01310010009", "外修费用");
    	}
    	
        return tResult;
    }
    
	   public ObjectList search(DBConnection con,SearchEvent event) throws Exception
	    {
	        DBEngine.checkCon(con);
	        String sql = "select * from " + getTableName();
	   
	        String sql1 = "select count(*) from " + getTableName() + " ";
	        
	        Conditions eventCs = event.toConditions();
	       // eventCs.add("1=1");
	        int rsCount = DBEngine.doCount(con, sql1, eventCs);
//	      int totalCount = 0;
//	      if(getTableName().equalsIgnoreCase(OrderItem.TABLE_NAME))
//	          totalCount = OrderItem.getTotalRecordNum(con);
//	      if(getTableName().equalsIgnoreCase(OrderItem.TABLE_NAME))
//	          totalCount = Item.getTotalRecordNum(con); 
//	      DateUtil startTime = new DateUtil();
//	      long start = System.currentTimeMillis();
	        Conditions cs = event.toConditions(); 
	        DBResult result = DBEngine.doSelect(con,sql,cs,event);
	        ObjectList list = ObjectList.fromRsMini(getClass(),result.getRs(),event.getPageSize(),event.getPageNum(), rsCount);
//	      long end = System.currentTimeMillis();
//	      DateUtil endTime = new DateUtil();
//	      PerformanceLog.addLog(con, getClass(), sql, rsCount, event.toConditions(), event.getOrderField(), startTime, endTime, end - start);
	        result.clear();
	        return list;
	    }

	private String getTableName() {
		
		return "t_product_out_category";
	}
	
}
